
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
  <head>
    <meta charset="utf-8" />
    <title>数据类型 &#8212; Python 3.7.8 文档</title>
    <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <script type="text/javascript" src="../_static/translations.js"></script>
    
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    
    <link rel="search" type="application/opensearchdescription+xml"
          title="在 Python 3.7.8 文档 中搜索"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="关于这些文档" href="../about.html" />
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="copyright" title="版权所有" href="../copyright.html" />
    <link rel="next" title="datetime --- 基本的日期和时间类型" href="datetime.html" />
    <link rel="prev" title="codecs --- 编解码器注册和相关基类" href="codecs.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <link rel="canonical" href="https://docs.python.org/3/library/datatypes.html" />
    
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    
    
    
    
    <style>
      @media only screen {
        table.full-width-table {
            width: 100%;
        }
      }
    </style>
 

  </head><body>
  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>导航</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="总目录"
             accesskey="I">索引</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python 模块索引"
             >模块</a> |</li>
        <li class="right" >
          <a href="datetime.html" title="datetime --- 基本的日期和时间类型"
             accesskey="N">下一页</a> |</li>
        <li class="right" >
          <a href="codecs.html" title="codecs --- 编解码器注册和相关基类"
             accesskey="P">上一页</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">3.7.8 Documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Python 标准库</a> &#187;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="快速搜索" type="text" name="q" />
          <input type="submit" value="转向" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>    

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="data-types">
<span id="datatypes"></span><h1>数据类型<a class="headerlink" href="#data-types" title="永久链接至标题">¶</a></h1>
<p>本章所描述的模块提供了许多专门的数据类型，如日期和时间、固定类型的数组、堆队列、双端队列、以及枚举。</p>
<p>Python也提供一些内置数据类型，特别是，<a class="reference internal" href="stdtypes.html#dict" title="dict"><code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code></a>、 <a class="reference internal" href="stdtypes.html#list" title="list"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a>、<a class="reference internal" href="stdtypes.html#set" title="set"><code class="xref py py-class docutils literal notranslate"><span class="pre">set</span></code></a>、<a class="reference internal" href="stdtypes.html#frozenset" title="frozenset"><code class="xref py py-class docutils literal notranslate"><span class="pre">frozenset</span></code></a>、以及 <a class="reference internal" href="stdtypes.html#tuple" title="tuple"><code class="xref py py-class docutils literal notranslate"><span class="pre">tuple</span></code></a>。<a class="reference internal" href="stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> 这个类是用来存储Unicode字符串的，而 <a class="reference internal" href="stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> 和 <a class="reference internal" href="stdtypes.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a> 这两个类是用来存储二进制数据的。</p>
<p>本章包含以下模块的文档：</p>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="datetime.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">datetime</span></code> --- 基本的日期和时间类型</a><ul>
<li class="toctree-l2"><a class="reference internal" href="datetime.html#available-types">有效的类型</a></li>
<li class="toctree-l2"><a class="reference internal" href="datetime.html#timedelta-objects"><code class="xref py py-class docutils literal notranslate"><span class="pre">timedelta</span></code> 类对象</a></li>
<li class="toctree-l2"><a class="reference internal" href="datetime.html#date-objects"><code class="xref py py-class docutils literal notranslate"><span class="pre">date</span></code> 对象</a></li>
<li class="toctree-l2"><a class="reference internal" href="datetime.html#datetime-objects"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime</span></code> 对象</a></li>
<li class="toctree-l2"><a class="reference internal" href="datetime.html#time-objects"><code class="xref py py-class docutils literal notranslate"><span class="pre">time</span></code> 对象</a></li>
<li class="toctree-l2"><a class="reference internal" href="datetime.html#tzinfo-objects"><code class="xref py py-class docutils literal notranslate"><span class="pre">tzinfo</span></code> 对象</a></li>
<li class="toctree-l2"><a class="reference internal" href="datetime.html#timezone-objects"><code class="xref py py-class docutils literal notranslate"><span class="pre">timezone</span></code> 对象</a></li>
<li class="toctree-l2"><a class="reference internal" href="datetime.html#strftime-and-strptime-behavior"><code class="xref py py-meth docutils literal notranslate"><span class="pre">strftime()</span></code> 和 <code class="xref py py-meth docutils literal notranslate"><span class="pre">strptime()</span></code> 的行为</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="calendar.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">calendar</span></code> --- 日历相关函数</a></li>
<li class="toctree-l1"><a class="reference internal" href="collections.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">collections</span></code> --- 容器数据类型</a><ul>
<li class="toctree-l2"><a class="reference internal" href="collections.html#chainmap-objects"><code class="xref py py-class docutils literal notranslate"><span class="pre">ChainMap</span></code> 对象</a><ul>
<li class="toctree-l3"><a class="reference internal" href="collections.html#chainmap-examples-and-recipes"><code class="xref py py-class docutils literal notranslate"><span class="pre">ChainMap</span></code> 例子和方法</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="collections.html#counter-objects"><code class="xref py py-class docutils literal notranslate"><span class="pre">Counter</span></code> 对象</a></li>
<li class="toctree-l2"><a class="reference internal" href="collections.html#deque-objects"><code class="xref py py-class docutils literal notranslate"><span class="pre">deque</span></code> 对象</a><ul>
<li class="toctree-l3"><a class="reference internal" href="collections.html#deque-recipes"><code class="xref py py-class docutils literal notranslate"><span class="pre">deque</span></code> 用法</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="collections.html#defaultdict-objects"><code class="xref py py-class docutils literal notranslate"><span class="pre">defaultdict</span></code> 对象</a><ul>
<li class="toctree-l3"><a class="reference internal" href="collections.html#defaultdict-examples"><code class="xref py py-class docutils literal notranslate"><span class="pre">defaultdict</span></code> 例子</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="collections.html#namedtuple-factory-function-for-tuples-with-named-fields"><code class="xref py py-func docutils literal notranslate"><span class="pre">namedtuple()</span></code> 命名元组的工厂函数</a></li>
<li class="toctree-l2"><a class="reference internal" href="collections.html#ordereddict-objects"><code class="xref py py-class docutils literal notranslate"><span class="pre">OrderedDict</span></code> 对象</a><ul>
<li class="toctree-l3"><a class="reference internal" href="collections.html#ordereddict-examples-and-recipes"><code class="xref py py-class docutils literal notranslate"><span class="pre">OrderedDict</span></code> 例子和用法</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="collections.html#userdict-objects"><code class="xref py py-class docutils literal notranslate"><span class="pre">UserDict</span></code> 对象</a></li>
<li class="toctree-l2"><a class="reference internal" href="collections.html#userlist-objects"><code class="xref py py-class docutils literal notranslate"><span class="pre">UserList</span></code> 对象</a></li>
<li class="toctree-l2"><a class="reference internal" href="collections.html#userstring-objects"><code class="xref py py-class docutils literal notranslate"><span class="pre">UserString</span></code> 对象</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="collections.abc.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">collections.abc</span></code> --- 容器的抽象基类</a><ul>
<li class="toctree-l2"><a class="reference internal" href="collections.abc.html#collections-abstract-base-classes">容器抽象基类</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="heapq.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">heapq</span></code> --- 堆队列算法</a><ul>
<li class="toctree-l2"><a class="reference internal" href="heapq.html#basic-examples">基本示例</a></li>
<li class="toctree-l2"><a class="reference internal" href="heapq.html#priority-queue-implementation-notes">优先队列实现说明</a></li>
<li class="toctree-l2"><a class="reference internal" href="heapq.html#theory">理论</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="bisect.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">bisect</span></code> --- 数组二分查找算法</a><ul>
<li class="toctree-l2"><a class="reference internal" href="bisect.html#searching-sorted-lists">搜索有序列表</a></li>
<li class="toctree-l2"><a class="reference internal" href="bisect.html#other-examples">其他示例</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="array.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">array</span></code> --- 高效的数值数组</a></li>
<li class="toctree-l1"><a class="reference internal" href="weakref.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">weakref</span></code> --- 弱引用</a><ul>
<li class="toctree-l2"><a class="reference internal" href="weakref.html#weak-reference-objects">弱引用对象</a></li>
<li class="toctree-l2"><a class="reference internal" href="weakref.html#example">示例</a></li>
<li class="toctree-l2"><a class="reference internal" href="weakref.html#finalizer-objects">终结器对象</a></li>
<li class="toctree-l2"><a class="reference internal" href="weakref.html#comparing-finalizers-with-del-methods">比较终结器与 <code class="xref py py-meth docutils literal notranslate"><span class="pre">__del__()</span></code> 方法</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="types.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">types</span></code> --- 动态类型创建和内置类型名称</a><ul>
<li class="toctree-l2"><a class="reference internal" href="types.html#dynamic-type-creation">动态类型创建</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#standard-interpreter-types">标准解释器类型</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#additional-utility-classes-and-functions">附加工具类和函数</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#coroutine-utility-functions">协程工具函数</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="copy.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">copy</span></code> --- 浅层 (shallow) 和深层 (deep) 复制操作</a></li>
<li class="toctree-l1"><a class="reference internal" href="pprint.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pprint</span></code> --- 数据美化输出</a><ul>
<li class="toctree-l2"><a class="reference internal" href="pprint.html#prettyprinter-objects">PrettyPrinter 对象</a></li>
<li class="toctree-l2"><a class="reference internal" href="pprint.html#example">示例</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="reprlib.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">reprlib</span></code> --- 另一种 <code class="xref py py-func docutils literal notranslate"><span class="pre">repr()</span></code> 实现</a><ul>
<li class="toctree-l2"><a class="reference internal" href="reprlib.html#repr-objects">Repr 对象</a></li>
<li class="toctree-l2"><a class="reference internal" href="reprlib.html#subclassing-repr-objects">子类化 Repr 对象</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="enum.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">enum</span></code> --- 枚举类型支持</a><ul>
<li class="toctree-l2"><a class="reference internal" href="enum.html#module-contents">模块内容</a></li>
<li class="toctree-l2"><a class="reference internal" href="enum.html#creating-an-enum">创建一个 Enum</a></li>
<li class="toctree-l2"><a class="reference internal" href="enum.html#programmatic-access-to-enumeration-members-and-their-attributes">对枚举成员及其属性的程序化访问</a></li>
<li class="toctree-l2"><a class="reference internal" href="enum.html#duplicating-enum-members-and-values">复制枚举成员和值</a></li>
<li class="toctree-l2"><a class="reference internal" href="enum.html#ensuring-unique-enumeration-values">确保唯一的枚举值</a></li>
<li class="toctree-l2"><a class="reference internal" href="enum.html#using-automatic-values">使用自动设定的值</a></li>
<li class="toctree-l2"><a class="reference internal" href="enum.html#iteration">迭代</a></li>
<li class="toctree-l2"><a class="reference internal" href="enum.html#comparisons">比较运算</a></li>
<li class="toctree-l2"><a class="reference internal" href="enum.html#allowed-members-and-attributes-of-enumerations">允许的枚举成员和属性</a></li>
<li class="toctree-l2"><a class="reference internal" href="enum.html#restricted-enum-subclassing">受限的 Enum 子类化</a></li>
<li class="toctree-l2"><a class="reference internal" href="enum.html#pickling">封存</a></li>
<li class="toctree-l2"><a class="reference internal" href="enum.html#functional-api">可用 API</a></li>
<li class="toctree-l2"><a class="reference internal" href="enum.html#derived-enumerations">派生的枚举</a><ul>
<li class="toctree-l3"><a class="reference internal" href="enum.html#intenum">IntEnum</a></li>
<li class="toctree-l3"><a class="reference internal" href="enum.html#intflag">IntFlag</a></li>
<li class="toctree-l3"><a class="reference internal" href="enum.html#flag">标志</a></li>
<li class="toctree-l3"><a class="reference internal" href="enum.html#others">其他事项</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="enum.html#interesting-examples">有趣的示例</a><ul>
<li class="toctree-l3"><a class="reference internal" href="enum.html#omitting-values">省略值</a><ul>
<li class="toctree-l4"><a class="reference internal" href="enum.html#using-auto">使用 <code class="xref py py-class docutils literal notranslate"><span class="pre">auto</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="enum.html#using-object">使用 <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="enum.html#using-a-descriptive-string">使用描述性字符串</a></li>
<li class="toctree-l4"><a class="reference internal" href="enum.html#using-a-custom-new">使用自定义的 <code class="xref py py-meth docutils literal notranslate"><span class="pre">__new__()</span></code></a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="enum.html#orderedenum">OrderedEnum</a></li>
<li class="toctree-l3"><a class="reference internal" href="enum.html#duplicatefreeenum">DuplicateFreeEnum</a></li>
<li class="toctree-l3"><a class="reference internal" href="enum.html#planet">Planet</a></li>
<li class="toctree-l3"><a class="reference internal" href="enum.html#timeperiod">TimePeriod</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="enum.html#how-are-enums-different">各种枚举有何区别？</a><ul>
<li class="toctree-l3"><a class="reference internal" href="enum.html#enum-classes">枚举类</a></li>
<li class="toctree-l3"><a class="reference internal" href="enum.html#enum-members-aka-instances">枚举成员（即实例）</a></li>
<li class="toctree-l3"><a class="reference internal" href="enum.html#finer-points">细节要点</a><ul>
<li class="toctree-l4"><a class="reference internal" href="enum.html#supported-dunder-names">支持 <code class="docutils literal notranslate"><span class="pre">__dunder__</span></code> 名称</a></li>
<li class="toctree-l4"><a class="reference internal" href="enum.html#supported-sunder-names">支持的 <code class="docutils literal notranslate"><span class="pre">_sunder_</span></code> 名称</a></li>
<li class="toctree-l4"><a class="reference internal" href="enum.html#enum-member-type"><code class="docutils literal notranslate"><span class="pre">Enum</span></code> 成员类型</a></li>
<li class="toctree-l4"><a class="reference internal" href="enum.html#boolean-value-of-enum-classes-and-members"><code class="docutils literal notranslate"><span class="pre">Enum</span></code> 类和成员的布尔值</a></li>
<li class="toctree-l4"><a class="reference internal" href="enum.html#enum-classes-with-methods">带有方法的 <code class="docutils literal notranslate"><span class="pre">Enum</span></code> 类</a></li>
<li class="toctree-l4"><a class="reference internal" href="enum.html#combining-members-of-flag">组合 <code class="docutils literal notranslate"><span class="pre">Flag</span></code> 的成员</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h4>上一个主题</h4>
  <p class="topless"><a href="codecs.html"
                        title="上一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">codecs</span></code> --- 编解码器注册和相关基类</a></p>
  <h4>下一个主题</h4>
  <p class="topless"><a href="datetime.html"
                        title="下一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">datetime</span></code> --- 基本的日期和时间类型</a></p>
  <div role="note" aria-label="source link">
    <h3>本页</h3>
    <ul class="this-page-menu">
      <li><a href="../bugs.html">提交 Bug</a></li>
      <li>
        <a href="https://github.com/python/cpython/blob/3.7/Doc/library/datatypes.rst"
            rel="nofollow">显示源代码
        </a>
      </li>
    </ul>
  </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>导航</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="总目录"
             >索引</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python 模块索引"
             >模块</a> |</li>
        <li class="right" >
          <a href="datetime.html" title="datetime --- 基本的日期和时间类型"
             >下一页</a> |</li>
        <li class="right" >
          <a href="codecs.html" title="codecs --- 编解码器注册和相关基类"
             >上一页</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">3.7.8 Documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >Python 标准库</a> &#187;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="快速搜索" type="text" name="q" />
          <input type="submit" value="转向" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">版权所有</a> 2001-2020, Python Software Foundation.
    <br />
    Python 软件基金会是一个非盈利组织。
    <a href="https://www.python.org/psf/donations/">请捐助。</a>
    <br />
    最后更新于 6月 29, 2020.
    <a href="../bugs.html">发现了问题</a>？
    <br />
    使用<a href="http://sphinx.pocoo.org/">Sphinx</a>2.3.1 创建。
    </div>

  </body>
</html>